RAIS  3.2
C:/Projekte/RAIS/Specific Masks/LoginPage.aspx.cs
Go to the documentation of this file.
00001 
00029 using System;
00030 using System.Data;
00031 using System.Configuration;
00032 using System.Collections;
00033 using System.Web;
00034 using System.Web.Security;
00035 using System.Web.UI;
00036 using System.Web.UI.WebControls;
00037 using System.Web.UI.WebControls.WebParts;
00038 using System.Web.UI.HtmlControls;
00039 using RAIS.ApplicationLogicLayer;
00040 using RAIS;
00041 
00042 using RAIS.Common.UserManagement;
00043 using Cultures = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.Culture>;
00044 using FunctionRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole>;
00045 
00046 namespace RAIS.UI.SpecificMasks
00047 {
00051     public partial class LoginPage : System.Web.UI.Page
00052     {        
00053                 //*********************************************************************
00054                 #region Properties
00055 
00058                 protected UserData CurrentUser
00059                 {
00060                         get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00061                 }
00062                 #endregion
00063                 #region Event handlers
00064         protected void Page_PreLoad(object sender, EventArgs e)
00065         {
00066             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00067         }
00079         protected void Page_Load(object sender, EventArgs e)
00080         {
00081                         this.Response.Cache.SetNoStore();
00082                         if (this.UserIsLoggedIn())
00083                 UI.Common.AccessManagement.RedirectToHome(this);
00084             else
00085             {
00086                                 RAIS.ApplicationLogicLayer.DynamicMaskManagement.InitializeDAL();
00087                                 RAIS.ApplicationLogicLayer.MessageManagement.InitializeDAL();
00088                                 RAIS.ApplicationLogicLayer.TableManagement.InitializeDAL();
00089                                 RAIS.ApplicationLogicLayer.UserManagement.InitializeDAL();
00090                                 this.InitializeLocalization();
00091 
00092                                 this.Session[UI.Common.Constants.PAGE_ACCESS_RIGHTS_TAG] = null;
00093                 UserData lastUser = (UserData)this.Session[UI.Common.Constants.LAST_USER_TAG];
00094                 this.DisplayUserData(lastUser);
00095                 this.Session[UI.Common.Constants.LAST_USER_TAG] = null; //for avoiding unintended use (Bug #8)
00096                 if (lastUser != null)
00097                 {
00098                     UI.Common.Localisation.TranslatePageToLanguage(this, this.SelectedLanguage);
00099                     this.Session[UI.Common.Constants.LAST_USER_TAG] = null;
00100                 }
00101                                 this.SetFocus(this.TXTusername);
00102             }
00103         }
00112         protected void BTNaccount_Click(object sender, EventArgs e)
00113         {
00114                         UserData user = new UserData();
00115                         user.Language = this.SelectedLanguage;
00116                         this.Session[UI.Common.Constants.CURRENT_USER_TAG] = user;
00117 
00118                         this.Response.Redirect("~/AccountRequest.aspx");
00119         }
00133         protected void BTNlogin_Click(object sender, EventArgs e)
00134         {
00135             if (this.LoginUser(this.TXTusername.Text, this.TXTpassword.Text))
00136             {
00137                 if (this.CBchangepassword.Checked == true && this.CurrentUser.FunctionalRole.Type!=FunctionRole.FunctionRoleType.Guest)
00138                 {
00139                     Server.Transfer("ChangePassword.aspx"); 
00140                 }
00141                 else
00142                 {
00143                                         UI.Common.UserManagement.InitializeAllMasksUserAccessRights(this);
00144                                         //switch (this.CurrentUser.Type.Type)
00145                                         switch (this.CurrentUser.FunctionalRole.Type)
00146                                         {
00147                                                 //case RAIS.Common.UserManagement.UserData.UserType.Admin:
00148                                                 //case RAIS.Common.UserManagement.UserData.UserType.Regulator:
00149                                                 case FunctionRole.FunctionRoleType.Administrator:
00150                                                 case FunctionRole.FunctionRoleType.Regulator:
00151                             if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_INPUT, this))
00152                                 this.Response.Redirect("~/Input.aspx");
00153                             if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_QUERY, this))
00154                                 this.Response.Redirect("~/Query.aspx");
00155                             if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_STATISTICS, this))
00156                                 this.Response.Redirect("~/Statistics.aspx");
00157                             else
00158                                 this.Response.Redirect("~/Default.aspx");
00159                                 break;
00160                                                 //case RAIS.Common.UserManagement.UserData.UserType.Licensee:
00161                                                 //case RAIS.Common.UserManagement.UserData.UserType.PublicBody:
00162                                                 case FunctionRole.FunctionRoleType.Licensee:
00163                                                 case FunctionRole.FunctionRoleType.PublicBody:
00164                                 if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_QUERY, this))
00165                                     this.Response.Redirect("~/Query.aspx");
00166                                 if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_STATISTICS, this))
00167                                     this.Response.Redirect("~/Statistics.aspx");
00168                                 else
00169                                     this.Response.Redirect("~/Default.aspx");
00170                                 break;
00171                                                 default:
00172                                 if (UI.Common.UserManagement.AccessToCategoryAllowed(RAIS.Common.Constants.CATEGORY_NAME_STATISTICS, this))
00173                                     this.Response.Redirect("~/Statistics.aspx");
00174                                 else
00175                                     this.Response.Redirect("~/Default.aspx");
00176                                 break;
00177                                         }
00178                                         //UI.Common.AccessManagement.RedirectToHome(this);
00179                 }
00180             }
00181             else
00182             {
00183                 this.LoginFailure();
00184                 this.DisplayLoginError();
00185             }
00186         }
00198         protected void DDLlanguage_SelectedIndexChanged(object sender, EventArgs e)
00199         {
00200             UI.Common.Localisation.TranslatePageToLanguage(this, this.SelectedLanguage);
00201         }
00202         #endregion
00203                 //*********************************************************************
00204                 #region Private helper methods
00205 
00210         private bool UserIsLoggedIn()
00211         {
00212             return this.Session[UI.Common.Constants.CURRENT_USER_TAG] != null;
00213         }
00223         private bool LoginUser(string userLoginName, string userPassword)
00224         {
00225             try
00226             {
00227                 UserData user = UserManagement.GetUserData(userLoginName);
00228 
00229                 if(user != null && user.IsActive                                                
00230                                         && user.Password == UserData.HashPassword(userPassword) )
00231                 {
00232                     FormsAuthentication.SetAuthCookie(userLoginName, false);
00233 
00234                     user.Language = this.SelectedLanguage;
00235 
00236                     FunctionRoles functionalRoles = RAIS.ApplicationLogicLayer.UserManagement.FunctionalRoles;
00237                     user.FunctionalRole.Attributes = functionalRoles[user.FunctionalRole.Name].Attributes;
00238 
00239                     this.Session[UI.Common.Constants.CURRENT_USER_TAG] = user;
00240                     this.LBLerror.Visible = false;
00241 
00242                                         return (ApplicationLogicLayer.UserManagement.LoginUser(user));
00243                 }
00244                 else
00245                     return false;
00246             }
00247             catch(Exception)
00248             {
00249                 return false;
00250             }
00251         }
00255         private void LoginFailure()
00256         {
00257             FormsAuthentication.SignOut();
00258             this.Session[UI.Common.Constants.CURRENT_USER_TAG] = null;
00259         }
00263         private void InitializeLocalization()
00264         {
00265             string strOldSelection = this.SelectedLanguage;
00266 
00267             if (this.SelectedLanguage == "")
00268                 Session["IsRightToLeft"] = false;
00269             else
00270             {
00271                 Session["IsRightToLeft"] = System.Globalization.CultureInfo.GetCultureInfo(RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages[this.SelectedLanguage].LCID).TextInfo.IsRightToLeft;
00272                 Session["CultureName"] = System.Globalization.CultureInfo.GetCultureInfo(RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages[this.SelectedLanguage].LCID).Name;
00273             }
00274             
00275 
00276             UI.Common.Localisation.InitializeLanguagesSelection(this.DDLlanguage.Items);
00277 
00278             if (strOldSelection != null && strOldSelection.Length != 0)
00279                 this.SelectedLanguage = strOldSelection;
00280             else
00281             if( !this.SelectCurrentSystemLnaguage() )
00282             {
00283                 this.SelectedLanguage = RAIS.Common.Constants.DEFAULT_LANGUAGE;
00284             }
00285         }
00290         private bool SelectCurrentSystemLnaguage()
00291         {
00292             System.Globalization.CultureInfo sessionCulture = new System.Globalization.CultureInfo(UI.Common.Constants.ENGLISH_CULTURE_LCID);
00293             Cultures supportedLanguages = RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages;
00294             if ((Request.UserLanguages != null) && (!string.IsNullOrEmpty(Request.UserLanguages[0])))
00295             {
00296                 System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(Request.UserLanguages[0]);
00297                 sessionCulture = supportedLanguages.ContainsKey(ci.NativeName) || ci.Parent.LCID == 127 ? ci : ci.Parent;
00298             }
00299             
00300             if (supportedLanguages.ContainsKey(sessionCulture.NativeName))
00301             {
00302                 this.SelectedLanguage = sessionCulture.NativeName;
00303                 return true;
00304             }
00305             else
00306             {
00307                 sessionCulture = new System.Globalization.CultureInfo(UI.Common.Constants.ENGLISH_CULTURE_LCID);
00308                 if (supportedLanguages.ContainsKey(UI.Common.Constants.ENGLISH_CULTURE_NAME))
00309                 {
00310                     this.SelectedLanguage = UI.Common.Constants.ENGLISH_CULTURE_NAME;
00311                     return true;
00312                 }
00313                 else
00314                     return false;
00315             }
00316         }
00324         private void DisplayUserData(UserData user)
00325         {
00326             if (user != null)
00327             {
00328                 //this.TXTusername.Text = user.Login;
00329                 if (this.DDLlanguage.Items.FindByText(user.Language) != null)
00330                 {
00331                     this.SelectedLanguage = user.Language;
00332                     UI.Common.Localisation.TranslatePageToLanguage(this, this.SelectedLanguage);
00333                 }
00334                 else
00335                     this.SelectedLanguage = RAIS.Common.Constants.DEFAULT_LANGUAGE;
00336             }
00337         }
00341         private void DisplayLoginError()
00342         {
00343             this.LBLerror.Text = Localisation.Translate(RAIS.Common.Messages.LOGIN_ERROR_MESSAGE,
00344                                                         RAIS.Common.Messages.TRANSLATION_CONTEXT,
00345                                                         RAIS.Common.Constants.DEFAULT_LANGUAGE,
00346                                                         this.SelectedLanguage);
00347             this.LBLerror.Visible = true;
00348         }
00354         private string SelectedLanguage
00355         {
00356             get
00357             {
00358                 return this.DDLlanguage.Text;
00359             }
00360             set
00361             {
00362                 this.DDLlanguage.SelectedValue = value;
00363             }
00364         }
00365         #endregion
00366 
00367         protected void CBchangepassword_CheckedChanged(object sender, EventArgs e)
00368         {
00369 
00370         }
00371     }
00372 }